<?php
/**
 * Created by PhpStorm.
 * User: fengbob
 * Date: 2018/2/21
 * Time: 09:19
 */

use yii\helpers\Url;

$web = Url::base();
?>


<div class="form-horizontal" id="data_form">
    <input type="hidden" id="id" name="id" class="form-control"
           value="<?= isset($item['id']) != null ? $item['id'] : '' ?>">

    <div class="form-group">
        <label class="control-label col-lg-2" for="name"><span
                class="font-color-attention">*</span>名称：</label>
        <div class="col-lg-10">
            <input type="text" id="name" name="name" class="form-control"
                   value="<?= $item != null ? $item['name'] : '' ?>">
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-lg-2" for="sort"><span
                class="font-color-attention">*</span>排序：</label>
        <div class="col-lg-10">
            <input type="text" id="sort" name="sort" class="form-control"
                   value="<?= $item != null ? $item['sort'] : '' ?>">
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-lg-2" for="brief_introduction"><span
                class="font-color-attention">*</span>简介：</label>
        <div class="col-lg-10">
            <input type="text" id="brief_introduction" name="brief_introduction" class="form-control"
                   value="<?= $item != null ? $item['brief_introduction'] : '' ?>">
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-lg-2" for="contact_man"><span
                class="font-color-attention">*</span>联系人：</label>
        <div class="col-lg-10">
            <input type="text" id="contact_man" name="contact_man" class="form-control"
                   value="<?= $item != null ? $item['contact_man'] : '' ?>">
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-lg-2" for="contact_phone"><span
                class="font-color-attention">*</span>联系电话：</label>
        <div class="col-lg-10">
            <input type="number" id="contact_phone" name="contact_phone" class="form-control"
                   value="<?= $item != null ? $item['contact_phone'] : '' ?>">
        </div>
    </div>


    <!--上传图片开始-->
    <form id="upload_image_submit_form" enctype="multipart/form-data" method="post"
          action=<?= \app\librarys\Tools::urlBase() . '/main/upload-image-handler' ?> target="swiper_edit_target">
        <div class="form-group">
            <label class="control-label col-lg-2">上传图片:</label>
            <div class="product-mod col-lg-10">
                <div class="upload-img">
                    <div class="uploadImg">
                        <input class="upload-img-box" type="file" onchange="uploadImage(this)"
                               name="uploadImg" id="uploadImg">
                        <input type="hidden" name="img_cord" id="img_cord"/>
                    </div>
                    <a href="javascript:void(0)" class="btn btn-warning">选择图片(jpeg,png,jpg)</a>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-lg-2"></label>
            <div class="product-mod col-lg-10">

                <div id="imgSingle_Sure">
                    <div class="pre_imgs">
                        <?php if (!empty($item['image_id'])): ?>
                            <img src="<?= \app\models\File::getFile($item['image_id'])['url'] ?>"
                                 onerror="showErrorImage(this)">
                        <?php endif ?>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--上传图片结束-->



    <div class="form-group">
        <label class="control-label col-lg-2" for="status"><span
                class="font-color-attention">*</span>状态：</label>
        <div class="col-lg-4">
            <select class='select-group' id="status" name="status">
                <option value="1" <?php echo $item['status'] == '1' ? 'selected' : '' ?>>支付宝小程序</option>
                <option value="2" <?php echo $item['status'] == '2' ? 'selected' : '' ?>>微信小程序</option>
            </select>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-lg-2" for="begin_datetime"><span
                class="font-color-attention">*</span>开通时间：</label>
        <div class="col-lg-4">
            <span class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd"
                  data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">
                <input class="form-control" size="16" type="text" readonly id="begin_datetime" name="begin_datetime"
                       placeholder="开通时间"
                       value="<?= $item != null ? \app\librarys\Tools::getDatetimeFormat($item['begin_datetime'], 'Y-m-d') : '' ?>">
                <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
            </span>
        </div>
    </div>


    <div class="form-group">
        <label class="control-label col-lg-2" for="end_datetime"><span
                class="font-color-attention">*</span>失效时间：</label>
        <div class="col-lg-4">
            <span class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd"
                  data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">
                <input class="form-control" size="16" type="text" readonly id="end_datetime" name="end_datetime"
                       placeholder="失效时间"
                       value="<?= $item != null ? \app\librarys\Tools::getDatetimeFormat($item['end_datetime'], 'Y-m-d') : '' ?>">
                <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
            </span>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-lg-2" for="is_on">启用：</label>
        <div class="col-lg-10">
            <div class="checkbox-switch-wrapper">
                <input class="checkbox-switch" type="checkbox" id="is_on" name="is_on"
                    <?php
                    if (isset($item['is_on']) && $item['is_on'] == 1) {
                        echo 'checked="checked"';
                    } else if (!isset($item['is_on'])) {
                        echo 'checked="checked"';
                    }
                    ?>
                >
                <div class="checkbox-switch-circle"></div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $('.form_date').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    });
</script>
<script type="text/javascript" src="<?= $web ?>/js/jcrop/jcrop.single.js"></script>
<script type="text/javascript">
    function uploadImage(obj) {
        previewSingleChange(obj, 1, 1, getImgPathFun);
    }

    function getImgPathFun() {
        $imgCord = $("input[name='imgCord']").val();
        $("#img_cord").val($imgCord);

        $("#swiper_edit_target").html('');
        $("#upload_image_submit_form").submit();
        $("#swiper_edit_target").unbind().load(function () {
            try {
                var result = JSON.parse($("#swiper_edit_target").contents().find("body").html());
                if (result.status == 0) {
                    var path = '<?= $web?>' + result.data.path;
                    if (result.data.path) {
                        setImgPath(result.data.path);
                    }

                    var html = '<img src="' + path + '" style="width: 200px; margin-left: 10px; margin-top: 10px">';
                    $("#imgSingle_Sure").html('').append(html);
                    closeCutImage();
                } else {
                    errorDialog(result.message);
                }
            } catch (err) {
                errorDialog("保存出错");
            }
        });
    }

</script>